package redisLearning;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.HashMap;
import java.util.Map;

public class redisHashDemo {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        try(Jedis jedis = jedisPool.getResource()) {
            test1(jedis);
        }
    }

    private static void test1(Jedis jedis) {
        jedis.flushAll();
        jedis.hset("key", "f1", "1");
        Map<String, String> map = new HashMap<>();
        map.put("f2", "2");
        map.put("f3", "3");
        jedis.hset("key", map);

        System.out.println(jedis.hget("key", "f1"));
        System.out.println(jedis.hget("key", "f2"));
        System.out.println(jedis.hget("key2", "f3"));
        System.out.println(jedis.hget("key", "f4"));

        System.out.println(jedis.hexists("key", "f1"));
        System.out.println(jedis.hexists("key", "f12"));

        System.out.println(jedis.hdel("key", "f1"));
        System.out.println(jedis.hexists("key", "f1"));

        System.out.println(jedis.hkeys("key"));
        System.out.println(jedis.hvals("key"));

        System.out.println(jedis.hmget("key", "f2", "f3"));

        System.out.println(jedis.hlen("key"));

    }
}
